<?php

namespace util;


class SqlUtil
{

    public static function zeroTime() {
        return '1990-01-01 00:00:00';
    }

    public static function formatStandarTime($str) {
        $time = strtotime($str);
        return self::timestampToDatetime($time);
    }

    public static function datetime($t = null) {
        if(empty($t)) {
            $t = time();
        }
        return date('Y-m-d H:i:s', $t);
    }

    public static function timestampToDatetime($t = null) {
        if(empty($t)) {
            $t = time();
        }
        return date('Y-m-d H:i:s', $t);
    }

    public static function getDistanceByLal($lat, $lng, $name='distance'){
        $lat = floatval($lat);
        $lng = floatval($lng);
        $str = '6371 * 2 * ASIN(SQRT(POWER(SIN((' . $lat . ' - abs(lat)) * pi()/180 / 2), 2) + COS(' . $lat . ' * pi()/180 ) * COS(abs(lat) * pi()/180) * POWER(SIN((' . $lng . ' - lng) * pi()/180 / 2), 2) )) as ' . $name;
        return $str;
    }
}